package xyz.lisys.demo;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;

import androidx.activity.result.ActivityResultLauncher;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private ActivityResultLauncher<Intent> register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        bindEvent();
    }

    public void initData() {
        // 注册Activity返回参数
//        register = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
//            @Override
//            public void onActivityResult(ActivityResult result) {
//                Intent intent = result.getData();
//
//            }
//        });
//        register.launch(new Intent());
//        setResult(Activity.RESULT_OK, new Intent());

        // 获取values/strings下定义的内容
        // getString(R.string.app_name);

        // 获取元数据
//        PackageManager pm = getPackageManager();
//        try {
//            ActivityInfo info = pm.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
//            Bundle bundle = info.metaData;
//        } catch (PackageManager.NameNotFoundException e) {
//            throw new RuntimeException(e);
//        }
    }

    public void bindEvent() {
        Button button = findViewById(R.id.to_nav);
        button.setOnClickListener(view -> {
            // Intent intent = new Intent();
            // intent.setClass(MainActivity.this, FooActivity.class);
            Uri uri = Uri.parse("https://www.baidu.com");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        });
    }
}